<?php
namespace utils;

class FileTool
{
    public static function readAll($path)
    {
        return file_get_contents($path);
    }
    
    function readBytes($path)
    {        
        $handle = fopen($path, "rb");
        $data = fread($handle, filesize ($path));
        fclose($handle);
        return $data;
    }

    public static function writeAll($path,$str)
    {
        $ret = true;
        $h = fopen($path,"w");
        if(!fwrite($h,$str,strlen($str))) $ret=false;
        fclose($h);
        return $ret;
    }

    /**
     * 添加一行
     */
    public static function appendLine($path,$str)
    {
        $h = fopen($path,"a");
        fwrite($h,$str,strlen($str));
        fwrite($h,"\n",1);
        fclose($h);
    }
}
?>